package cn.tedu.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/*本类用于巩固map集合的迭代*/
public class Demo {
    public static void main(String[] args) {
        Map<Integer,String> map = new HashMap<>();
        //向map集合存入数据,注意方法是put
        map.put(9527,"白骨精");
        map.put(9528,"黑熊精");
        map.put(9529,"鲤鱼精");
        map.put(9530,"黄毛怪");
        map.put(9531,"黑熊精");
        //map.put(9527,"女儿国");
        System.out.println(map);
        Set<Integer> set = map.keySet();
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()){
            Integer key = it.next();
            String value = map.get(key);
            System.out.println(key+"="+value);
        }

        Set<Map.Entry<Integer, String>> set1 = map.entrySet();
        Iterator<Map.Entry<Integer, String>> it1 = set1.iterator();
        while(it1.hasNext()){
            Map.Entry<Integer, String> entry = it1.next();
            Integer key = entry.getKey();
            String vlaue = entry.getValue();
            System.out.println(key+": "+vlaue);
        }
    }













}
